<?php

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\AuthController;
use App\Http\Controllers\UserController;
use App\Http\Controllers\ThesisTopicController;
use App\Http\Controllers\TopicSelectionController;
use App\Http\Controllers\TaskBookController;
use App\Http\Controllers\ProposalReportController;
use App\Http\Controllers\ProposalDefenseController;
use App\Http\Controllers\GuidanceRecordController;
use App\Http\Controllers\ThesisDocumentController;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
    return $request->user();
});

// 公开路由
Route::post('/login', [AuthController::class, 'login']);

// 需要认证的路由
Route::middleware('auth:sanctum')->group(function () {
    // 用户相关
    Route::post('/logout', [AuthController::class, 'logout']);
    Route::get('/me', [AuthController::class, 'me']);
    
    // 用户管理（仅管理员）
    Route::middleware('role:admin')->group(function () {
        Route::apiResource('users', UserController::class);
    });

    // 论文题目相关
    Route::apiResource('thesis-topics', ThesisTopicController::class);
    
    // 选题相关
    Route::apiResource('topic-selections', TopicSelectionController::class);
    
    // 任务书相关
    Route::apiResource('task-books', TaskBookController::class);
    
    // 开题报告相关
    Route::apiResource('proposal-reports', ProposalReportController::class);
    
    // 开题答辩相关
    Route::apiResource('proposal-defenses', ProposalDefenseController::class);
    
    // 指导记录相关
    Route::apiResource('guidance-records', GuidanceRecordController::class);
    
    // 论文文档相关
    Route::apiResource('thesis-documents', ThesisDocumentController::class);
    Route::get('thesis-documents/{document}/download', [ThesisDocumentController::class, 'download']);
});
